home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Human Interface Toolbox / ReadLocation / readLocation.p < prev    next >
Encoding:
Text File  |  2000-09-28  |  2.3 KB  |  76 lines  |  [TEXT/CWIE]

  1. {
  2.     File:        readLocation.p
  3.  
  4.     Contains:    retrieves the map settings for longitude and latitude and
  5.                   the time offset from GMT
  6.   
  7.                   for more information, see Worldwide Development: Guide to System Software
  8.  
  9.     Written by: Greg Robbins    
  10.  
  11.     Copyright:    Copyright © 1991-1999 by Apple Computer, Inc., All Rights Reserved.
  12.  
  13.                 You may incorporate this Apple sample source code into your program(s) without
  14.                 restriction. This Apple sample source code has been provided "AS IS" and the
  15.                 responsibility for its operation is yours. You are not permitted to redistribute
  16.                 this Apple sample source code as "Apple sample source code" after having made
  17.                 changes. If you're going to re-distribute the source, we require that you make
  18.                 it clear in the source that the code was descended from Apple sample source
  19.                 code, but that you've made changes.
  20.  
  21.     Change History (most recent first):
  22.                 8/9/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  23.                 
  24.  
  25. }
  26.  
  27. PROGRAM location;
  28.  
  29. USES Types, Script, FixMath;
  30.  
  31. VAR
  32.     myMachineLocation: MachineLocation;
  33.     latExt, longExt: EXTENDED;
  34.     latDeg, latMin, longDeg, longMin: LONGINT;
  35.     theGmtDelta, hours, minutes, seconds: LONGINT;
  36.     
  37.     FUNCTION GetGmtDelta(myLocation: MachineLocation): LONGINT;
  38.     VAR
  39.         internalGmtDelta: LONGINT;
  40.     BEGIN
  41.         { change 3-byte integer to LONGINT }
  42.         internalGmtDelta := BAND(myLocation.gmtDelta,$00FFFFFF);
  43.         IF BTST(internalGmtDelta,23) THEN { sign extend }
  44.             internalGmtDelta := BOR(internalGmtDelta,$FF000000);
  45.         GetGmtDelta := internalGmtDelta;
  46.     END;
  47.  
  48. BEGIN
  49.     ReadLocation(myMachineLocation);
  50.     
  51.     { convert location to extended fraction }
  52.     latExt := Frac2X(myMachineLocation.latitude);
  53.     longExt := Frac2X(myMachineLocation.longitude);
  54.     
  55.     { convert location to degrees-minutes }
  56.     latDeg := TRUNC(latExt * 90);
  57.     latMin := TRUNC((latExt * 90 - latDeg) * 60);
  58.  
  59.     longDeg := TRUNC(longExt * 90);
  60.     longMin := TRUNC((longExt * 90 - longDeg) * 60);
  61.     
  62.     { find time zone w.r.t. GMT }
  63.     theGmtDelta := GetGmtDelta(myMachineLocation);
  64.     hours := theGmtDelta DIV 3600;
  65.     minutes := (theGmtDelta MOD 3600) DIV 60;
  66.     seconds := theGmtDelta MOD 60;
  67.     
  68.     { negative values indicate South or West }
  69.     WriteLn('latitude:  ', latDeg, CHR($A1), latMin, CHR($27));
  70.     WriteLn('longitude: ', longDeg, CHR($A1), longMin, CHR($27));
  71.     
  72.     { negative values indicate West }
  73.     WriteLn('time from GMT: ', hours:3, ' h ', minutes:3, ' m ', 
  74.         seconds:2, ' s');
  75. END.
  76.